/**
 * **************** Copyright (C) *****************
 * <p/>
 * Version       Date            Author
 * ─────────────────────────────────────
 * V1.0        2017/6/17         yellowlgx
 * <p/>
 * **************** End of Head *******************
 */
package com.skyworth.ui.newrecycleview;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

/**
 * @author : yellowlgx
 * @ClassName NewRecycleViewHolder
 * @Description : TODO
 * @date : 2017/6/17 15:43
 */
public class NewRecycleViewHolder<T> extends RecyclerView.ViewHolder
{
    private boolean isNewdata = false;
    private T mCurT;

    public NewRecycleViewHolder(View itemView)
    {
        super(itemView);
    }

    public void refreshUI()
    {
//        if (!isNewdata)
//            return;

        if (itemView instanceof NewRecycleAdapterItem)
            ((NewRecycleAdapterItem) itemView).refreshUI();

        isNewdata = false;
    }

    public void setData(T data, int position)
    {
        if (data == null || !data.equals(mCurT))
        {
            isNewdata = true;
        } else
        {
            isNewdata = false;
        }
        mCurT = data;
        if (itemView instanceof NewRecycleAdapterItem)
            ((NewRecycleAdapterItem) itemView).onUpdateData(data, position);
    }

    public void clearItem()
    {
        mCurT = null;
        isNewdata = true;
        if (itemView instanceof NewRecycleAdapterItem)
            ((NewRecycleAdapterItem) itemView).clearItem();
    }

    public void destroy()
    {
        mCurT = null;
        isNewdata = true;
        if (itemView instanceof NewRecycleAdapterItem)
            ((NewRecycleAdapterItem) itemView).destroy();
    }
}